<?php


namespace app\api\controller\v5;


use app\common\models\Datum;
use app\common\models\DatumCate;

class Gudge extends BaseController
{
    //判断单词拼写对错
    public function index()
    {
        $data_get = input('get.');
        $datum = new Datum();

        $res = $datum->where('id', $data_get['id'])
            ->where('desc', $data_get['desc'])
            ->field('id,title,English,American,video,desc,example,translate,else')
            ->find()
            ->toArray();

        $result = $res['title'] == $data_get['word'] ? true : false;
        if ($result == false ){
            $error = new \app\common\models\Error();
            $data2 = DatumCate::where(['id' => $data_get['datum_cate_id']])
                ->field('grade_id,course_id')
                ->find()->toArray();
            $res['api_member_id'] = $this->user_id;
            $res['datum_cate_id'] = $data_get['datum_cate_id'];
            $res['datum_id'] = $data_get['id'];
            $res['type'] = 1;
            unset($res['id']);
            //合并
            $data = array_merge($res, $data2);
            $error->save($data);
        }
        return sucessMsg(200, '获取成功', $result);
    }
}